package com.jiji.miaosha.mapper.provide;

import com.jiji.miaosha.entity.Order;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

public class OrderMapperProvider {

    public String insertOrder(final Map<String, Object> map) {
        Order order = (Order) map.get("order");
        SQL sql = new SQL() {
            {
                INSERT_INTO("order_info");
                if (order.getId() != null) {
                    VALUES("id", "'" + order.getId() + "'");
                }
                if (order.getUserId() != null) {
                    VALUES("user_id", String.valueOf(order.getUserId()));
                }
                if (order.getItemId() != null) {
                    VALUES("item_id", String.valueOf(order.getItemId()));
                }
                if (order.getItemPrice() != null) {
                    VALUES("item_price", String.valueOf(order.getItemPrice()));
                }
                if (order.getAmount() != null) {
                    VALUES("amount", String.valueOf(order.getAmount()));
                }
                if (order.getOrderPrice() != null) {
                    VALUES("order_price", String.valueOf(order.getOrderPrice()));
                }
                if (order.getPromoId() != null) {
                    VALUES("promo_id", String.valueOf(order.getPromoId()));
                }
            }
        };
        return sql.toString();
    }
}
